package com.example.teaching_server.repository;

import com.example.teaching_server.entity.ExtracurricularRecording;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 课外活动录制数据访问层
 */
@Repository
public interface ExtracurricularRecordingRepository extends JpaRepository<ExtracurricularRecording, Long> {

    /**
     * 根据学期ID和班级ID查询录制记录
     */
    @Query("SELECT r FROM ExtracurricularRecording r WHERE r.termId = :termId AND r.classId = :classId ORDER BY r.activityDate DESC, r.startTime DESC")
    List<ExtracurricularRecording> findByTermIdAndClassId(@Param("termId") Integer termId, @Param("classId") Integer classId);

    /**
     * 根据学期ID查询录制记录
     */
    @Query("SELECT r FROM ExtracurricularRecording r WHERE r.termId = :termId ORDER BY r.activityDate DESC, r.startTime DESC")
    List<ExtracurricularRecording> findByTermId(@Param("termId") Integer termId);

    /**
     * 根据班级ID查询录制记录
     */
    @Query("SELECT r FROM ExtracurricularRecording r WHERE r.classId = :classId ORDER BY r.activityDate DESC, r.startTime DESC")
    List<ExtracurricularRecording> findByClassId(@Param("classId") Integer classId);
}
